import Vue from 'vue'
import VueRouter from 'vue-router'

// const originalPush = VueRouter.prototype.push;
// VueRouter.prototype.push = function push(location) {
//     return originalPush.call(this, location).catch(err => err)
// };

const Home = () =>
    import ('@/views/Home.vue')
const User = () =>
    import ('@/views/user/User.vue')
const About = () =>
    import ('@/views/About.vue')
const Alarm = () =>
    import ('@/views/alarm/Alarm.vue')
const Utils = () =>
    import ('@/views/utils/Utils.vue')
const AlarmReport = () =>
    import ('@/views/alarm/Report.vue')
const AlarmList = () =>
    import ('@/views/alarm/Record.vue')
const AlarmCfg = () =>
    import ('@/views/alarm/Config.vue')
const Test = () =>
    import ('@/views/test/Test.vue')
const Test2 = () =>
    import ('@/views/test/Test.vue')
const Apitest = () =>
    import ('@/views/apitest/ApiTest.vue')
Vue.use(VueRouter)

const utils = {
    path: '/utils',
    meta: { title: 'Utils' },
    name: 'Utils',
    component: Utils
}


const user = {
    path: '/user',
    meta: { title: 'User' },
    name: 'User',
    component: User
}
const about = {
    path: '/about',
    meta: { title: 'About' },
    name: 'About',
    component: About
}
const test = {
    path: '/test',
    meta: { title: 'Test' },
    name: 'Test',
    component: Test
}
const apitest = {
    path: '/apitest',
    meta: { title: 'ApiTest' },
    name: 'ApiTest',
    component: Apitest
}
const test2 = {
    path: '/test2',
    meta: { title: 'Test' },
    name: 'Test2',
    component: Test2
}

const alarm = {
    path: '/alarm',
    meta: { title: 'Alarm' },
    redirect: '/alarm/record',
    children: [{
            path: 'report',
            meta: { title: 'Alarm|Report' },
            component: AlarmReport
        },
        {
            path: '/record',
            name: 'Record',
            meta: { title: 'Alarm|Record' },
            component: AlarmList,
            // beforeEnter: (to, from, next) => {
            //     next()
            // },
        },
        {
            path: 'config',
            name: 'config',
            meta: { title: 'Alarm|Configuration' },
            component: AlarmCfg
        }
    ]

}

const routes = [{
        path: '',
        meta: { title: 'Home' },
        redirect: 'Home',
    },
    {
        path: '/home',
        meta: { title: 'Home' },
        name: 'Home',
        component: Home
    },
    test,
    test2,
    {
        path: '/alarm',
        meta: { title: 'Alarm' },
        component: Alarm,
        redirect: '/alarm/record',
        children: [{
                path: 'report',
                meta: { title: 'Alarm|Report' },
                component: AlarmReport,
            },
            {
                path: 'record',
                meta: { title: 'Alarm|Record' },
                component: AlarmList,
            },
            {
                path: 'config',
                meta: { title: 'Alarm|Configuration' },
                component: AlarmCfg
            }
        ]

    },
    apitest,
    utils,
    about,
    user,
]

const router = new VueRouter({
    routes,
    mode: 'history'
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.title
    next()

})
export default router